import java.util.*;

class Person{
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }


    //定位
    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}

public class Test2 {

    public static void main(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
    }

    public static void main3(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(12,122);
        hashBucket.put(3,33);
        hashBucket.put(4,44);
        hashBucket.put(14,144);
        hashBucket.put(5,55);
        hashBucket.put(16,166);

        System.out.println(hashBucket.get(16));

    }

    //直接定制法
    public int firstUniqChar(String s){
        int[] count = new int[26];
        for (int i = 0; i < s.length();i++){
            char ch = s.charAt(i);
            count[ch - 'a']++;
        }
        for (int i = 0; i < s.length();i++){
            char ch = s.charAt(i);
            if (count[ch - 'a'] == 1){
                return i;
            }
        }
        return -1;
    }


    public static void main1(String[] args) {
        Map<String,Integer> map = new TreeMap<>();
        map.put("hello",2);//相当于往搜索树中插入数据//和key比较
        map.put("abcd",3);
        map.put("dff",5);
        map.put("ettr",8);
        map.put("ettr",9);//相同的key会更新val值

        //Set<String> set = map.keySet();

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for (Map.Entry<String,Integer> entry : entrySet){
            System.out.println("key: " + entry.getKey()+" val: "+entry.getValue());
        }

        //System.out.println(map.get("abcd"));
        //System.out.println(map.getOrDefault("abdcf",78));
        //map.remove("abcd");
        //System.out.println(map.getOrDefault("abcd",8));
        //System.out.println("hhj");
    }

    public static void main2(String[] args) {
        //set当中的元素不可以重复
        Set<String> strings = new TreeSet<>();
        strings.add("hello");
        strings.add("fbg");
        strings.add("ef");
        strings.add("ef");//这里底层treeMap,每次存储元素放在map的可key上
        //strings.clear();

        Iterator<String> it = strings.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
    }
}
